import DotPersonnelAddTpl from './case.html';
import _ from 'underscore';
import Util from '../../../../common-component/util/util.js';
import upload from '../../../../common-component/upload/upload';
import Table from '../../../../common-component/table/table.js';
import ServiceCommon from '../../../service-common/service-common.js';
import API from '../../../../api/Api.js';

import "../case.scss";

export default function DotPersonnelAdd() {

    $("#app-container").html( DotPersonnelAddTpl({name: '新闻列表'}) );

    const licenseImgHeader = upload("#upload-img-wrap",{itemsWrap: '#js-item-wrap'}),_this = this,v = $('#update_dot').easyform();
    _this.params = {};

    //实例化编辑器
    // var UEHintText = "请输入文章内容，不能为空";
    UM.delEditor('myEditor');
    var ue = UM.getEditor('myEditor');
    // editorHtml = ue.getContent(),
    // editorText = ue.getContentTxt().substring(0,50);
    $(".js-handle-save").on('click', function(e) {
        const $this = $(this);
        _this.params.operType = $this.data('handle');
        operType = _this.params.operType;
        v.submit();
    })

    v.success = function (ef){//验证成功
        _this.params = $(ef.form).serializeObject(_this.params);
        _this.params.limitMoney = parseInt(_this.params.limitMoney*100)
        $.ajax({
            url: API.addEmployee,
            type: 'post',
            data:_this.params,
            success(data) {
                let {result:success,error} = data;
                if(success){
                    window.location.href = '#/dot-personnel'
                }else{
                    Util.alertMessage(error)
                }
            }
        });
    }
    const handlers = {
        params:{},
        init: function(evt) {
            const _this = this;
            this.bindEvent();
        },
        /**
         * 绑定事件
         */
        bindEvent: function() {
            const _this = this;
            $(".js-handle").on('click', function(e) {
                const $this = $(this), handle = $this.data('handle');
                _this[handle] && _this[handle]($this, e);
            })
            return this;
        },
        /**
         * 厂家合同证明
         */
        licenseImg: function() {
            licenseImgHeader.setOptions({
                maxNumber:1,
                itemsWrap: '#js-item-wrap',
                memory: '#js-memory',
                hasFile: false,
            }).open();
        },
        /**
         * 保存
         */
        submitBtn: function() {

        },
        /**
         * 审核
         */
        reviewBtn: function() {

        },
        /**
         * 返回
         */
        return: function() {
            window.location.href = '#/news'
        },
        /**
         * 品类
         */
        categorysJson: function(cur, e) {
            const fill = cur.data('fill'), $ipt = $(fill);
            ServiceCommon._queryCategory(obj=>{
                console.log(obj)
                let name = [], ids = [];
                obj.forEach((item, idx)=>{
                    name.push(item.categoryName)
                    ids.push(item.categoryCode)
                })
                cur.val(name.join(','));
                $ipt.val(ids.join(','));
            });
        },
        /**
         * 所属网点
         */
        stationName: function(cur, e) {
            const fill = cur.data('fill'), $ipt = $(fill);
            ServiceCommon._queryRepairingBlock(obj=>{
                cur.val(obj.stationName);
                $ipt.val(obj.id);
            });
        },
        /**
         * 品类
         */
        clear: function($this) {
            $this.siblings('input').val('');
        },
    }

    handlers.init();

}